package org.budo.tencent.response;

import org.budo.support.http.client.Response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author lmw
 */
@Getter
@Setter
@ToString
public class OpenIdResponse extends AbstractResponse {
    private static final long serialVersionUID = -7106857281535413804L;

    private String openId;

    public OpenIdResponse() {}

    public OpenIdResponse(Response response) {
        this.setResponse(response);

        String responseBody = response.getBody();
        String json = responseBody.replace("callback(", "").replace(");", "");
        JSONObject jsonObject = JSON.parseObject(json);

        this.setOpenId(jsonObject.getString("openid"));
    }
}